import { EmployeesApi } from '@/api/Employees.api.js'
import { BillApi } from '@/api/Bill.api.js'
import { SysWelfarePercentEmployeeConfigApi } from '@/api/SysWelfarePercentEmployeeConfig.api.js'
import { SysWelfarePercentConfigDetailApi } from '@/api/SysWelfarePercentConfigDetail.api.js'
import { SysWelfarePercentEmployeeAdjustConfigApi } from '@/api/SysWelfarePercentEmployeeAdjustConfig.api.js'
import { SysWelfarePercentNoConfigApi } from '@/api/SysWelfarePercentNoConfig.api.js'
import { SysWelfarePercentAreaConfigApi } from '@/api/SysWelfarePercentAreaConfig.api.js'
import { FormGongjijinFilter, FormGongjijinFilterItem, FormGongjijinFilterOnlyViewItem, FormGongjijinTitle, FormGongjijin, FormGongjijinItem } from './EBformData.js'
import { gongjijinThead, gongjijinjiluThead, gongjijinListThead } from './EBtableHead.js'
import _cloneDeep from 'clone-deep'
import { Common } from '@/utils/common.js'
import { EBbase } from './EBbase.js'
import { timingSafeEqual } from 'crypto'

export default {
  props: {
    serviceFeeType: {
      type: Number,
      default: 0
    },
    // isOnlyView: {
    //   type: Boolean,
    //   default: false
    // },
    isInsuranceInfoSet: {
      type: Boolean,
      default: false
    }
  },

  computed: {
    setFormGongjijinFilterItem () {
      if (this.isDataOperator && this.isBatch) {
        this.formGongjijinFilterItem.map((item, index) => {
          if (['insuredTime', 'payMonth', 'description'].indexOf(item.model) !== -1) {
            item.isShow = false
          }
        })
      } else {
      }
      return this.formGongjijinFilterItem
    }
  },

  data () {
    return {
      isOnlyView: true,
      canEditor: null,
      isCreateNew: false,
      selectedEmployeeId: [], // 选中的员工ID
      employeeId: '', // 员工ID
      companyId: '', // 公司ID
      companyName: '', // 公司名称
      insuranceId: '', // 保险ID
      formGongjijinFilter: _cloneDeep(FormGongjijinFilter),
      formGongjijinFilterItem: _cloneDeep(FormGongjijinFilterItem),
      formGongjijinFilterOnlyViewItem: _cloneDeep(FormGongjijinFilterOnlyViewItem),
      formGongjijinTitle: _cloneDeep(FormGongjijinTitle),
      formGongjijin: _cloneDeep(FormGongjijin),
      formGongjijinItem: _cloneDeep(FormGongjijinItem),
      rules: {},
      SecurityId: '', // 公积金方案ID
      arrListDown: {
        securitys: [],
        securitysPlay2: []
      },
      gongjijinThead: _cloneDeep(gongjijinThead),
      gongjijinjiluThead: _cloneDeep(gongjijinjiluThead),
      gongjijinListThead: _cloneDeep(gongjijinListThead),
      tableData: [],
      recordTableData: [],
      tableComone: {
        pageIndex: 1, // 页码
        totalRows: 0, // 总条数
        pageSize: 10 // 当前页面展示条数
      },
      selectedId: '',
      configInfo: {},
      isNext: false,
      dateOptions: {
        disabledDate (date) {
          const disabledDay = date.getDate()
          const month = date.getMonth()
          const nowMonth = (new Date()).getMonth()
          if (month === nowMonth) {

          } else {
            return disabledDay !== 1
          }
        }
      },
      isCanSave: true,
      // currentSecurityGUID: null // 已选中的公积金编号
      employeeBasicInfo: null,
      isBatch: false,
      isBatchOut: true,// 判断进入入口，true时为花名册-勾选-参保信息设置
      isEdit: false,
      isBJtiaoji: false,
      tableListData: [],
      moreGongjijin: [],
      isFromRoster: null,
      isDataOperator: null, // 是否是管理员身份
      isCanSubmitBJtiaoji: true
    }
  },

  mounted () {
    this.employeeId = this.$route.query.employeeId // 员工ID
    this.companyId = this.$route.query.companyId // 公司ID
    this.companyName = this.$route.query.companyName // 公司名称
    this.isFromRoster = this.$route.query.isFromRoster // 是否从员工管理页面过来
    this.canEditor = !!(this.$route.query.checkEmployeeNum || this.$route.query.isCreateNew || this.$route.query.isBatch)
    this.isOnlyView = this.$route.query.isOnlyView
    this.isCreateNew = !!this.$route.query.isCreateNew
    this.selectedEmployeeId = JSON.parse(localStorage.getItem('selectedEmployeeId')) // 选中的员工
    this.employeeBasicInfo = JSON.parse(localStorage.getItem('employeeBasicInfo')) // 当前员工基本信息
    this.isDataOperator = JSON.parse(localStorage.getItem('isDataOperator')) // 是否是管理员身份

    this.isBatch = this.$route.query.isBatch // 是否批量
    this.isBatchOut = this.$route.query.isBatchOut // 是否批量
    console.log(this.isBatchOut,'_____isbatchout________')
    // this.getConfig()
    if (!this.canEditor && this.employeeBasicInfo) {
      this.employeeInsureDetails()
    }

    if (this.isOnlyView) {
      this.getConfigList()
    } else {
      this.getConfig()
    }

    this.getList()
  },

  methods: {
    // 监听所有调用的方法
    listenCall (methodsWords, ...values) {
      this[methodsWords](...values)
    },

    async handleSubmit (name) {
      var tempAmounts = []
      this.configInfo.details.map(item => {
        var aloneObg = { SecurityTypeCode: item.securityTypeCode }
        if (item.company) {
          aloneObg.CompanyBaseAmount = item.company.baseAmount
        }
        if (item.employee) {
          aloneObg.EmployeeBaseAmount = item.employee.baseAmount
        }
        tempAmounts.push(aloneObg)
      })
      console.log('tempAmounts: ', tempAmounts)

      var params = {
        id: this.insuranceId,
        securityType: 2, // 参保类型（1社会保险、2公积金）
        rangeGUID: this.formGongjijinFilter.securityGUID, // 公积金编号
        employeeGUID: this.employeeId, // 员工ID
        securityGUID: this.formGongjijinFilter.securityGUID, // 公积金方案
        insuredTime: this.formGongjijinFilter.insuredTime, // 参保时间
        description: this.formGongjijinFilter.description, // 备注
        amounts: tempAmounts
      }
      console.log('提交表单params: ', params)
      let res = await SysWelfarePercentEmployeeConfigApi.saveShebaoOrGongjijin(params)
      console.log('提交表单res: ', res)
      if (res.status === 200 && res.data.success) {
        this.$Message.success(res.data.message)
        this.isNext = true
        this.isEdit = false
        this.getList()
        this.$emit('saveSuccess', res.data.data)
      } else {
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
      }
    },

    async handleSubmitBatch (name) {
      let formSum = { ...this.formGongjijinFilter, ...this.formGongjijin }
      var tempAmounts = []

      // for (var item in this.formGongjijin) {
      //   console.log('item: ', item)
      //   console.log('this.formGongjijin: ', this.formGongjijin)
      //   var aloneObg = {
      //     SecurityTypeCode: item,
      //     CompanyBaseAmount: this.formGongjijin[item].Company.baseAmount,
      //     EmployeeBaseAmount: this.formGongjijin[item].Employee.baseAmount,
      //   }
      //   tempAmounts.push(aloneObg)
      // }
      this.configInfo.details.map(item => {
        var aloneObg = { SecurityTypeCode: item.securityTypeCode }
        if (item.company) {
          aloneObg.CompanyBaseAmount = item.company.baseAmount
        }
        if (item.employee) {
          aloneObg.EmployeeBaseAmount = item.employee.baseAmount
        }
        tempAmounts.push(aloneObg)
      })

      var params = {
        securityType: 2, // 参保类型（1社会保险、2公积金）
        rangeGUID: this.formGongjijinFilter.rangeGUIDs, // 公积金编号
        employeeIdList: this.selectedEmployeeId, // 员工ID
        securityGUID: this.formGongjijinFilter.rangeGUID, // 公积金方案
        insuredTime: this.formGongjijinFilter.insuredTime, // 参保时间
        description: this.formGongjijinFilter.description, // 备注
        amounts: tempAmounts
      }
      console.log('公积金 提交表单params: ', params)
      let res = await SysWelfarePercentEmployeeConfigApi.batchSaveShebaoOrGongjijin(params)
      console.log('公积金 提交表单res: ', res)
      if (res.status === 200 && res.data.success) {
        this.$Message.success(res.data.message)
        this.isNext = true
        this.$emit('saveSuccess', res.data.data)
      } else {
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
      }
    },

    // 公积金补缴调基
    async handleSubmitTiaoji () {
      this.isCanSubmitBJtiaoji = false
      var tempAmounts = []
      var tempEmployee = JSON.parse(localStorage.getItem('selectedEmployeeId'))
      this.configInfo.details.map(item => {
        var aloneObg = { SecurityTypeCode: item.securityTypeCode }
        if (item.company) {
          aloneObg.CompanyBaseAmount = item.company.baseAmount
        }
        if (item.employee) {
          aloneObg.EmployeeBaseAmount = item.employee.baseAmount
        }
        tempAmounts.push(aloneObg)
      })
      console.log('tempAmounts: ', tempAmounts)

      var params = {
        id: this.insuranceId,
        securityType: 2, // 参保类型（1社会保险、2公积金）
        rangeGUID: this.formGongjijinFilter.securityGUID, // 公积金编号
        employeeIdList: tempEmployee, // 员工ID
        CompanyGUID: this.companyId,
        securityGUID: this.formGongjijinFilter.securityGUID, // 公积金方案
        insuredTime: this.formGongjijinFilter.insuredTime, // 参保时间
        description: this.formGongjijinFilter.description, // 备注
        amounts: tempAmounts
      }
      console.log('提交表单params: ', params)
      let res = await SysWelfarePercentEmployeeAdjustConfigApi.save(params)
      console.log('提交表单res: ', res)
      if (res.status === 200 && res.data.success) {
        this.$Message.success(res.data.message)
        this.isNext = true
        this.$emit('saveSuccess', res.data.data)
      } else {
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
        var that = this
        setTimeout(() => {
          that.isCanSubmitBJtiaoji = true
        }, 1000);
      }
    },

    // 上一步
    handlepageUp () {
      if ([2, 23].indexOf(this.serviceFeeType) !== -1) { // 参保种类选择了'公积金' || '公积金+商保'
        Common.pageUp(this, 3)
      } else {
        Common.pageUp(this)
      }
    },

    // 下一步
    handlepageDown () {
      // Common.pageDown(this, 6) // '公积金'的下一个页面是'商保'，这个不会变
      if ([23, 123].indexOf(this.serviceFeeType) !== -1) { // 参保种类选择了'商业保险' || '社保+商保' || '公积金+商保' || '社保+公积金+商保'
        Common.pageUp(this, 6)
      } else if ([2, 12].indexOf(this.serviceFeeType) !== -1) { // 参保种类选择了'公积金' || '社保+公积金'
        Common.pageUp(this, 7)
      } else {
        Common.pageUp(this)
      }
    },

    // 表格选择操作
    handleOnSelectChange (value) {
      let arr = value.map((item) => {
        return item.id
      })
      this.selectedId = arr.join(',')
      console.log('列表勾选', this.selectedId)
    },

    // 修改
    handleModify () {
      this.isNext = true
      if (this.formGongjijinFilter.insuredTime === '') {
        this.formGongjijinFilter.insuredTime = new Date()
      }
      this.$emit('handleModify', 4)
    },

    // 输入补缴月数计算参保时间
    toCountDate (form, month) {
      EBbase.toCountDate(this.formGongjijinFilter, month)
    },

    // 输入参保时间计算补缴月数
    toCountMonth (form, date) {
      EBbase.toCountMonth(this.formGongjijinFilter, date)
    },

    // 返回员工花名册列表
    goEmployeeBookList () {
      this.$router.push({
        path: '/EmployeeBook',
        name: 'EmployeeBook',
        query: {
          companyId: this.companyId,
          companyName: this.companyName
        }
      })
    },

    // 根据ID获取员工参保基数配置信息
    async getConfig (id) {
      var params = {
        SecurityType: 2,
        CompanyGUID: this.companyId,
        EmployeeGUID: this.employeeId
      }
      if (id) {
        params.id = id
      }
      let res = await SysWelfarePercentEmployeeConfigApi.getConfig(params)
      console.log(res,'getConfig')
      if (res.status === 200 && res.data.success && res.data.data.config) {
        var result = res.data.data
        this.configInfo = result.config // 保险信息
        this.insuranceId = result.config.id // 保险id
        // this.formGongjijinFilter.insuredTime = result.config.securityGUID ? result.config.add.declareDate : '' // 参保时间(没有公积金编号时，参保时间为空)
        this.formGongjijinFilter.payMonth = result.config.payMonth // 补缴月份

        if (!result.config.securityGUID) {
          if (this.canEditor) {
            this.formGongjijinFilter.insuredTime = new Date()
          } else {
            this.formGongjijinFilter.insuredTime = ''
          }
        } else {
          this.formGongjijinFilter.insuredTime = result.config.add.declareDate
        }

        // if (!result.config.securityGUID && this.isOnlyView) {
        //   console.log('没有securityGUID && 仅查看时')
        //   this.formGongjijinFilter.insuredTime = ''
        // }

        // EBbase.toCountMonth(this.formGongjijinFilter, new Date(result.config.add.declareDate))
        for(let i in result.securitys) {
          result.securitys[i].label =  result.securitys[i].text
          result.securitys[i].value =  result.securitys[i].securityGUID
        }
        this.arrListDown.securitys = result.securitys // 公积金编号列表
        // this.formGongjijinFilter.securityGUID = result.config.securityGUID // 公积金编号
        // var tempSecuritys = result.securitys // 公积金编号下拉框
        // if (result.securitys) {
        //   result.securitys.map(item => {
        //     this.arrListDown.securitys.push({label: item.text, value: item.value, securityGUID: item.securityGUID})
        //   })
        // }

        // if (result.config.rangeGUID) {
        //   this.getPlanList(result.config.rangeGUID, 2, this.arrListDown)
        // }

        EBbase.parseConfigInfoIsOnlyView(this.configInfo, this.formGongjijinFilter, this.tableData)
        this.formGongjijinFilter.rangeGUID = result.config.securityGUID // 公积金编号
        this.formGongjijinFilter.securityGUID = result.config.securityGUID // 公积金方案
        this.formGongjijinFilter.description = result.config.description // 备注
        console.log(this.formGongjijinFilter,'this.formGongjijinFilter')
        Object.keys(this.tableData[1]).forEach(key => {
          this.tableData[1][key] = this.tableData[1][key] + '%'
        })
      }
    },

    // 根据员工ID和参保类型获取参保明细信息
    async getConfigList (id) {
      var params = {
        SecurityType: 2,
        CompanyGUID: this.companyId,
        EmployeeGUID: this.employeeId
      }
      if (id) {
        params.id = id
      }
      let res = await SysWelfarePercentConfigDetailApi.getList(params)
      console.log('🌼🌼🌼 🍃🍃🍃 res: ', res)
      if (res.status === 200 && res.data.success) {
        res.data.data.map(table => {
          table.parsingData = []
          EBbase.readAddModelValToTable(table.details, table.parsingData, 'baseAmount')
          EBbase.readAddModelValToTable(table.details, table.parsingData, 'percent')

          Object.keys(table.parsingData[1]).forEach(key => {
            table.parsingData[1][key] = table.parsingData[1][key] ? table.parsingData[1][key] + '%' : ''
          })
        })
        this.moreGongjijin = res.data.data
        console.log('❌❌❌ this.moreGongjijin: ', this.moreGongjijin)
      }
    },

    // 根据ID获取员工参保基数配置信息-公积金调基
    async getTiaojiConfig (companyId, employeeId) {
      var params = {
        SecurityType: 2,
        CompanyGUID: companyId,
        EmployeeIdList: employeeId
      }
      let res = await SysWelfarePercentEmployeeAdjustConfigApi.getConfig(params)
      if (res.status === 200 && res.data.success && res.data.data.config) {
        var result = res.data.data
        this.configInfo = result.config // 保险信息
        this.insuranceId = result.config.id // 保险id
        this.formGongjijinFilter.payMonth = result.config.payMonth // 补缴月份

        if (!result.config.securityGUID) {
          if (this.canEditor) {
            this.formGongjijinFilter.insuredTime = new Date()
          } else {
            this.formGongjijinFilter.insuredTime = ''
          }
        } else {
          this.formGongjijinFilter.insuredTime = result.config.add.declareDate
        }
        
        this.arrListDown.securitys = result.securitys // 公积金编号列表
        console.log('😱😱😱😱😱😱')
        console.log(this.arrListDown)

        this.formGongjijinFilter.rangeGUID = result.config.securityGUID // 公积金编号
        this.formGongjijinFilter.securityGUID = result.config.securityGUID // 公积金方案
        this.formGongjijinFilter.description = result.config.description // 备注

        EBbase.parseConfigInfoIsOnlyView(this.configInfo, this.formGongjijinFilter, this.tableData)
        Object.keys(this.tableData[1]).forEach(key => {
          this.tableData[1][key] = this.tableData[1][key] + '%'
        })
      }
    },

    // 根据ID获取员工参保基数配置信息(批量)
    async getBatchConfig () {
      var params = {
        SecurityType: 2,
        EmployeeIdList: this.selectedEmployeeId
      }
      let res = await SysWelfarePercentEmployeeConfigApi.getBatchConfig(params)
      if (res.status === 200 && res.data.success && res.data.data.config) {
        var result = res.data.data
        this.configInfo = result.config // 保险信息
        this.insuranceId = result.config.id // 保险id
        for(let i in result.securitys) {
          result.securitys[i].label =  result.securitys[i].securityNO
          result.securitys[i].value =  result.securitys[i].id
        }
        this.arrListDown.securitys = result.securitys // 公积金编号列表
        // this.formGongjijinFilter.securityGUID = result.config.securityGUID // 公积金编号
        // var tempSecuritys = result.securitys // 公积金编号下拉框
        // if (result.securitys) {
        //   result.securitys.map(item => {
        //     this.arrListDown.securitys.push({label: item.text, value: item.value})
        //   })
        // }

        // if (result.config.rangeGUID) {
        //   this.getPlanList(result.config.rangeGUID, 1, this.arrListDown)
        // }

        this.formGongjijinFilter.rangeGUID = result.securitys[0].id // 公积金编号
        this.formGongjijinFilter.rangeGUIDs = result.securitys[0].rangeGUID // 公积金编号
        this.formGongjijinFilter.securityGUID = result.securitys[0].id // 公积金方案
        this.formGongjijinFilter.description = result.config.description // 备注
        // this.getAddModel2(result.securitys[0].id)
      } else {
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
      }
    },

    // 获取公积金编号
    async getAddModel (securityType, securityGUID, companyId) {
      console.log('getAddModel 参数securityType: ', securityType)
      var params = {
        SecurityType: securityType,
        SecurityGUID: securityGUID,
        CompanyGUID: companyId
      }
      let res = await SysWelfarePercentEmployeeConfigApi.getAddModel(params)
      console.log('获取公积金编号res: ', res)
    },

    // 获取公积金方案
    async getPlanList (securityGUID, securityType, arr) {
      console.log('getPlanList 参数securityGUID: ', securityGUID)
      console.log('getPlanList 参数securityType: ', securityType)
      console.log('getPlanList 参数arr: ', arr)
      // this.arrListDown.securitysPlay1 = []
      // this.formGongjijinFilter.securityGUID = ''
      // var tempArr = []
      // var params = {
      //   CompanyGUID: this.companyId,
      //   SecurityType: securityType,
      //   SecurityNO: securityGUID
      // }
      // let res = await SysWelfarePercentNoConfigApi.getPlanList(params)
      // console.log('获取公积金方案res: ', res)
      // if (res.status === 200 && res.data.success) {
      //   res.data.data.map(item => {
      //     tempArr.push({label: item.text, value: item.value})
      //   })
      // } else {
      //   tempArr = []
      // }
      // this.arrListDown.securitysPlay1 = tempArr
      // this.allInsuranceNum = ''
    },

    // 拿到公积金方案后获取的公积金参数配置
    async getAddModel2 (selectId) {
      // this.arrListDown.securitys = []
      console.log('getAddModel2 参数selectId: ', selectId)
      this.arrListDown.securitys.map(item => {
        if (item.value === selectId) {
          // this.currentSecurityGUID = item.securityGUID
          this.formGongjijinFilter.securityGUID = item.securityGUID
        }
      })
      console.log('已选中的公积金编号是: ', this.formGongjijinFilter.securityGUID)
      console.log(this.isBatchOut,'公积金_isBatchOut')
      if(!this.isBatchOut){
        var params = {
          SecurityType: 2,
          CompanyGUID: this.companyId,
          SecurityGUID: this.formGongjijinFilter.securityGUID
        }
        let res = await SysWelfarePercentEmployeeConfigApi.getAddModel(params)
        console.log('getAddModel拿到公积金方案后获取的公积金参数配置res: ', res)
        if (res.status === 200 && res.data.success) {
          var result = res.data.data
          this.configInfo = result.config // 保险信息
          for(let i in result.securitys) {
            result.securitys[i].label =  result.securitys[i].text
            result.securitys[i].value =  result.securitys[i].securityGUID
          }
          this.arrListDown.securitys = result.securitys // 公积金编号列表
        }
      } else {
        var params = {
          SecurityType: 2,
          CompanyGUID: this.companyId,
          SecurityGUID: selectId,
          EmployeeIdList: this.selectedEmployeeId
        }
        let res = await SysWelfarePercentEmployeeConfigApi.getBatchConfig(params)
        console.log('getBatchConfig拿到公积金方案后获取的公积金参数配置res: ', res)
        if (res.status === 200 && res.data.success) {
          var result = res.data.data
          this.configInfo = result.config // 保险信息
          for(let i in result.securitys) {
            result.securitys[i].label =  result.securitys[i].securityNO
            result.securitys[i].value =  result.securitys[i].id
            if(result.securitys[i].id == selectId) {
              console.log(result.securitys[i].id,'result.securitys[i].id')
              console.log(result.securitys[i].rangeGUID,'result.securitys[i].rangeGUID')
              this.formShebaoFilter.rangeGUID = result.securitys[i].id
              this.formShebaoFilter.rangeGUIDs =  result.securitys[i].rangeGUID
            }
          }
          this.arrListDown.securitys = result.securitys // 公积金编号列表
        }
      }
    },

    // 默认基数改变时，重新计算缴纳金额
    async baseAmountOnBlur (baseAmount, precision, percent, section, rowIndex) {
      var params = {
        money: baseAmount, // 金额
        precision: precision, // 精度
        percent: percent // 比例
      }
      let res = await SysWelfarePercentAreaConfigApi.getTotalAmount(params)
      if (res.status === 200 && res.data.success) {
        console.log('计算单条缴纳金额res: ', res)
        if (res.status === 200 && res.data.success) {
          this.configInfo.details[rowIndex][section].totalAmount = res.data.data
        }
      }
    },

    // 搜索
    searchFn () {
      this.tableComone.pageIndex = 1
      this.query()
    },

    /**
     * 分页页码变动
     * @param {Number} val pageIndex
     */
    onChangePage (val) {
      this.tableComone.pageIndex = val
      this.query()
    },
    /**
     * 分页页码变动
     * @param {Number} val pageSize
     */
    onpageSizeChange (val) {
      this.tableComone.pageIndex = 1
      this.tableComone.pageSize = val
      this.query()
    },

    // 获取公积金记录
    async employeeInsureDetails (selectId) {
      console.log('...........................')
      var params = {
        CustomerId: this.companyId,
        EmployeeId: this.employeeId,
        Category: 2, // 1-社保，2-公积金，3-商保
        IdCardType: this.employeeBasicInfo.idType,
        IdCardNo: this.employeeBasicInfo.idCardNo,
        HasPaging: true,
        PageIndex: this.tableComone.pageIndex,
        PageSize: this.tableComone.pageSize
      }
      // var params = {
      //   CustomerId: '946FB851-F1AC-E911-80BF-509A4C9F0611',
      //   EmployeeId: '97B07F68-70A7-E911-80BE-509A4C9F0611',
      //   Category: 2, // 1-社保，2-公积金，4-商保
      //   IdCardType: 0,
      //   IdCardNo: '430124199211278967',
      //   HasPaging: true,
      //   PageIndex: 1,
      //   PageSize: 10,
      // }
      let res = await BillApi.employeeInsureDetails(params)
      console.log('获取社保记录res: ', res)
      if (res.status === 200 && res.data.success) {
        this.recordTableData = res.data.data
        this.tableComone.totalRows = res.data.totalRows
        this.recordTableData.map(row => {
          row.insureItems.map(item => { // 循环解析insureItems里面的companyFee、employeeFee值并赋到相应的key
            var sumStr = ''
            if (item.companyFee) {
              Object.keys(item.companyFee).forEach(key => {
                sumStr = item.category + 'companyFee' + key
                row[sumStr] = item.companyFee[key]
              })
            }

            if (item.employeeFee) {
              Object.keys(item.employeeFee).forEach(key => {
                sumStr = item.category + 'employeeFee' + key
                row[sumStr] = item.employeeFee[key]
              })
            }
          })
        })
        console.log('🐟 this.recordTableData: ', this.recordTableData)
      }
    },

    // 修改当前条
    handleEditRow (row) {
      console.log('社保修改当前条row: ', row)
      this.isEdit = true
      for (var item in row) {
        this.formGongjijinFilter[item] = row[item]
      }
      this.getConfig(row.id)
    },

    // 删除员工社保信息(单个)-确认删除
    async handleSureDelete (id) {
      let res = await SysWelfarePercentEmployeeConfigApi.delete({ id: id })
      if (res.data.success) {
        this.$Message.success(res.data.message)
        // if (this.$route.query.isBatch) {
        //   this.queryBatch()
        // } else {
        //   this.query()
        // }
        this.getList()
      } else {
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
      }
    },

    // 删除员工社保信息(批量)-确认删除
    async handleSureBatchDelete (securityGUID) {
      // var paramObj = {
      //   SecurityGUID: securityGUID,
      //   EmployeeIdList: this.selectedEmployeeId
      // }
      // console.log('🌙', paramObj)
      // let res = await SysWelfarePercentEmployeeCommercialConfigApi.batchDelete(paramObj)
      // if (res.data.success) {
      //   this.$Message.success(res.data.message)
      //   if (this.$route.query.isBatch) {
      //     this.queryBatch()
      //   } else {
      //     this.query()
      //   }
      // } else {
      //   
      //   this.$Message.error({
      //     content: res.data.message,
      //     // duration: 0,
      //     closable: true
      //   })
      // }
    },

    // 新增社保
    handleCreat () {
      this.insuranceId = ''
      Object.keys(this.formGongjijinFilter).forEach(key => {
        if (key !== 'insuredTime') {
          this.formGongjijinFilter[key] = '' // 表单内容置空
        }
      })
      this.formGongjijinFilter.insuredTime = new Date()
      this.isEdit = true
    },

    // 新增社保-批量
    handleBatchCreat () {
      this.insuranceId = ''
      Object.keys(this.formGongjijinFilter).forEach(key => {
        if (key !== 'id' && key !== 'insuredTime') {
          this.formGongjijinFilter[key] = '' // 表单内容置空
        }
      })

      this.formGongjijinFilter.employeeIdList = this.selectedEmployeeId
      this.isEdit = true
    },

    // 根据条件获取福利【五险一金-员工】基数比例参数配置
    async getList () {
      var params = {
        // Id: this.insuranceId,
        SecurityType: 2, // 参保类型（1社会保险、2公积金）
        EmployeeGUID: this.employeeId,
        CompanyGUID: this.companyId
      }
      let res = await SysWelfarePercentEmployeeConfigApi.getList(params)
      if (res.status === 200 && res.data.success) {
        this.tableListData = res.data.data
      } else {
        this.tableListData = []
      }
    },

    // 返回员工花名册列表
    goEmployeeBookList () {
      EBbase.goEmployeeBookList(this.$router, this.companyId, this.companyName)
    },

    // 返回员工管理
    goRoster () {
      EBbase.goRoster(this.$router)
    }
  }
}
